package com.lakeworks.decision.handler;

import com.lakeworks.common.domain.ticket.TktDecision;
import com.lakeworks.common.domain.ticket.TktTicket;
import com.lakeworks.decision.UpdateTicketDecision;
import com.lakeworks.decision.base.BaseDecisionHandler;
import com.lakeworks.decision.base.DecisionHandler;
import com.lakeworks.domain.vo.TicketBackVo;
import org.springframework.stereotype.Component;

@Component
public class UpdateTicketHandler extends BaseDecisionHandler implements DecisionHandler<UpdateTicketDecision> {

    @Override
    public TktDecision apply(UpdateTicketDecision decision) {
        TktTicket ticket = decision.getTktTicket();
        try {
            getMerchantAsync().ticketUpdate(TicketBackVo.builder()
                    .ticketId(ticket.getChannelTicketId())
                    .channelId(getChannelId(ticket.getOrderNo()))
                    .operator(decision.getOperator())
                    .remark(ticket.getRemark())
                    .tktTicketFiles(ticket.getTktTicketFiles()).build());
        }catch (Exception e){
             getLog().error("channel --- ticketUpdate---error:[{}]",e);
        }
        return getTktDecision(ticket, decision);
    }

}
